package com.lw.sbdemo2.web;

import com.lw.sbdemo2.common.base.BaseController;
import com.lw.sbdemo2.common.utils.IdUtils;
import com.lw.sbdemo2.common.vo.PageInfo;
import com.lw.sbdemo2.common.web.anno.Required;
import com.lw.sbdemo2.common.web.anno.ResultController;
import com.lw.sbdemo2.entity.TkExamUnitDict;
import com.lw.sbdemo2.service.TkExamUnitDictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>标题: 题库试题单元字典服务 - 请求控制层</p>
 * <p>描述: </p>
 * <p>版权: Copyright (c) 2019</p>
 * <p>公司: 山人行工作室</p>
 *
 * @version: 1.0
 * @author: LinWang
 * @date 2019-4-14
 */
@ResultController
@Api(description = "TkExamUnitDictController", tags = {"题库试题单元字典服务"})
@RequestMapping(value = "/tkExamUnitDict")
public class TkExamUnitDictController extends BaseController {

    /**
     * 题库试题单元字典服务
     */
    @Autowired
    private TkExamUnitDictService tkExamUnitDictService;

	@ApiOperation(value = "获取题库试题单元字典列表")
    @GetMapping("")
    public List<TkExamUnitDict> findList(TkExamUnitDict tkExamUnitDict) {
        return tkExamUnitDictService.findList(tkExamUnitDict);
    }

    @ApiOperation(value = "获取题库试题单元字典列表")
    @GetMapping("/getTermUnit")
    public List<Map<String , Object>> getTermUnit(TkExamUnitDict tkExamUnitDict) {
        return tkExamUnitDictService.getTermUnit(tkExamUnitDict);
    }

    @ApiOperation(value = "获取题库试题单元字典列表（分页）", response = PageInfo.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "query", value = "关键词", dataType = "string"),
            @ApiImplicitParam(name = "pageNum", value = "当前页码", required = true, dataType = "int"),
    })
    @GetMapping(value = "/page")
    public PageInfo<TkExamUnitDict> page(String query, @Required("pageNum") PageInfo pageInfo, TkExamUnitDict tkExamUnitDict) {
        return tkExamUnitDictService.findListPage(query, pageInfo, tkExamUnitDict);
    }

    @ApiOperation(value = "获取题库试题单元字典详细信息", notes = "根据url的id来获取题库试题单元字典详细信息")
    @ApiImplicitParam(name = "id", value = "题库试题单元字典ID", required = true, dataType = "String")
    @GetMapping("/{id}")
    public TkExamUnitDict get(@PathVariable String id) {
        return tkExamUnitDictService.getById(id);
    }

    @ApiOperation(value = "创建题库试题单元字典")
    @PostMapping("/insert")
    public void insert(TkExamUnitDict tkExamUnitDict) throws Exception {
		tkExamUnitDict.setCreatedTime(new Date());
        tkExamUnitDictService.checkName(tkExamUnitDict.getTermId(),tkExamUnitDict.getExamUnitName());
        tkExamUnitDict.setExamUnitId(IdUtils.uuid());
        tkExamUnitDictService.insert(tkExamUnitDict);
    }

    @ApiOperation(value = "更新题库试题单元字典详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "题库试题单元字典ID", required = true, paramType = "query", dataType = "String")
    })
    @PostMapping("/update")
    public void update(TkExamUnitDict tkExamUnitDict) throws Exception {
		tkExamUnitDict.setModifiedTime(new Date());
		tkExamUnitDictService.updateCheckName(tkExamUnitDict);
        tkExamUnitDictService.update(tkExamUnitDict);
    }

    @ApiOperation(value = "删除题库试题单元字典", notes = "删除题库试题单元字典")
    @ApiImplicitParam(name = "id", value = "题库试题单元字典ID", required = true, paramType = "query", dataType = "String")
    @PostMapping("/delete")
    public void deleteTkExamUnitDict(TkExamUnitDict tkExamUnitDict) {
        tkExamUnitDictService.delete(tkExamUnitDict);
    }

}
